package coreEngine;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;

public class LogInfo {
	private String fileName = "HLS_SatTrack_";
	private JTextArea ta;
	private DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
	private Date date;
	
	public LogInfo(JTextArea ta){
		this.ta=ta;
	}
	
	public JTextArea getTa() {
		return ta;
	}
	
	public String getFileName() {
		return fileName;
	}
	
	public void writeLogsToFile(){
		date = new Date();
		String dateAux = dateFormat.format(date);
		File file = new File(getFileName()+dateAux+".txt");
		BufferedWriter writer;
		try {
			writer = new BufferedWriter(new FileWriter(file, true));
			getTa().write(writer);
			writer.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} // true for append
		JOptionPane.showMessageDialog(null, "Log file "+file.getName()+" was created successfully ", "INFO", JOptionPane.INFORMATION_MESSAGE);

	}

}
